package com.jxl.domain.handler.subject;

import com.jxl.common.enums.DeletedCodeEnum;
import com.jxl.common.enums.SubjectTypeEnum;
import com.jxl.domain.entity.SubjectAnswerBO;
import com.jxl.domain.entity.SubjectInfoBO;
import com.jxl.domain.entity.SubjectOptionBO;
import com.jxl.infra.basic.entity.SubjectBrief;
import com.jxl.infra.basic.entity.SubjectJudge;
import com.jxl.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 简答策略
 */
@Component
public class BriefHandler implements SubjectTypeHandler{
    @Resource
    private SubjectBriefService subjectBriefService;


    @Override
    public SubjectTypeEnum getHandlerType() {
        return SubjectTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectInfoBO.getSubjectId());
        subjectBrief.setSubjectAnswer(subjectInfoBO.getSubjectAnswer());
        subjectBrief.setIsDeleted(DeletedCodeEnum.UN_DELETE.getCode());
        subjectBriefService.insert(subjectBrief);
    }

    @Override
    public SubjectOptionBO query(Long id) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(id);
        subjectBrief.setIsDeleted(DeletedCodeEnum.UN_DELETE.getCode());
        List<SubjectBrief> query = subjectBriefService.query(subjectBrief);
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        if (query!=null && query.size()!=0){
            subjectOptionBO.setSubjectAnswer(query.get(0).getSubjectAnswer());
        }
        return subjectOptionBO;
    }
}
